package com.oitsm.mo.action;

import java.util.List;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.oitsm.commons.action.BaseAction;
import com.oitsm.mo.entity.DiscoverMeta;
import com.oitsm.plugin.cache.DiscoverMetaCache;
import com.oitsm.utils.JSONUtils;

/**
 * 自动发现Action
 * @author Arab Runner
 * Jul 31, 2011 12:23:04 PM
 */
@SuppressWarnings("serial")
public class DiscoverAction extends BaseAction {
	
	/**
	 * 获取可自动发现类型
	 * @return
	 * @throws Exception
	 */
	public String getDiscoverMeta()throws Exception{
		List<DiscoverMeta> metas = DiscoverMetaCache.getAllDiscoverMeta();
		
		String webContext = this.getContextPath();
		JSONArray ja = new JSONArray();
		for(DiscoverMeta n : metas){
			JSONObject jo = new JSONObject();
			jo.put("id", n.getId());
			jo.put("text", n.getText());
			jo.put("icon", webContext+n.getIcon());
			jo.put("desc", n.getDesc());
			ja.add(jo);
		}
		JSONUtils.write(this.getResponse(), ja.toString());
		return null;
	}
}
